#ifndef _DISPATCHER_H_INCLUDED_
#define _DISPATCHER_H_INCLUDED_
#include "core.h"
#include <sys/sysinfo.h>
const int DEFAULT_NUM_OF_THREADS = get_nprocs();; //to do：设置线程数为cpu数目
#include "threadPool.h"
const int BUFFER_SIZE = 2048;
//Reactor模式中的事件分发器
class Dispatcher
{
private:
    cycle_t& utils;
    threadPool workerPool;
   // module& modules;
    int serverSocket;
public:
    inline Dispatcher(cycle_t& util):
    utils(util), 
    workerPool(DEFAULT_NUM_OF_THREADS){};
    void dispatcher_cycle();
    void run(); // move your ass!
    ~Dispatcher() = default;
    void readEventHandler(connection_t* conn); //读事件处理函数
    void writeEventHandler(connection_t* conn); //写事件处理函数
    int localConnHandler(connection_t* conn, const char* buffer, int bytes); //用户连接处理函数
    int peerConnHandler(connection_t* conn, const char* buffer, int bytes); //对端连接处理函数
};


#endif